package com.aaa.sbms.service;

import com.aaa.sbms.dao.EmpDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class EmpServiceImpl implements EmpService {

    @Autowired(required = false)
    private EmpDao empDao;

    @Override
    public Map depts() {
        Map resutlMap = new HashMap();
        List<Map> depts = empDao.depts();
        resutlMap.put("list",depts);
        return resutlMap;
    }

    @Override
    public Map empPage(Map map) {
        int pageNo = Integer.valueOf(map.get("pageNo").toString());
        int pageSize = Integer.valueOf(map.get("pageSize").toString());
        int begin = (pageNo-1)*pageSize;
        map.put("begin",begin);
        map.put("pageSize",pageSize);
        List<Map> page = empDao.empPage(map);
        int total = empDao.empPageCount(map);
        HashMap<Object,Object> resultMap= new HashMap<>();
        resultMap.put("list",page);
        resultMap.put("total",total);
        return resultMap;
    }

    @Override
    public Map empSignPage(Map map) {
        int pageNo = Integer.valueOf(map.get("pageNo").toString());
        int pageSize = Integer.valueOf(map.get("pageSize").toString());
        int begin = (pageNo-1)*pageSize;
        map.put("begin",begin);
        map.put("pageSize",pageSize);
        List<Map> page = empDao.empSignPage(map);
        int total = empDao.empSignPageCount(map);
        Map resultMap= new HashMap();
        resultMap.put("list",page);
        resultMap.put("total",total);
        return resultMap;
    }

    @Override
    public Map empOne(int userid) {
        Map resutlMap = new HashMap();
        Map empOne = empDao.empOne(userid);
        resutlMap.put("list",empOne);
        return resutlMap;
    }
}
